package com.ffcs.web.utils;

import com.ffcs.web.model.dto.AccessToken;
import com.ffcs.web.model.dto.JsapiTicket;

public class JsSign {

	//微信支付商户开通后 微信会提供appid和appsecret和商户号partner
	private static String appid = CommonConfig.getProperty("APPID");
	private static String appsecret = CommonConfig.getProperty("APPSECRET");
	private static String partner = CommonConfig.getProperty("PARTNER");
	//这个参数partnerkey是在商户后台配置的一个32位的key,微信商户平台-账户设置-安全设置-api安全
	private static String partnerkey = CommonConfig.getProperty("PARTNERKEY");
	
	public static String getAccessToken(){
		String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
		url=url.replace("APPID",appid);
		url=url.replace("APPSECRET",appsecret);
		String result = HttpGetUtil.doGet2(url, "");
		if(null==result){
			return "error";
		}
		AccessToken accessToken=(AccessToken) JsonUtil.jsonToBean(result, AccessToken.class);
		return accessToken.getAccess_token();
	}
	
	public static String getJsapiTicket(){
		String url="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
		url=url.replace("ACCESS_TOKEN",JsSign.getAccessToken());
		String result = HttpGetUtil.doGet2(url, "");
		System.out.println(result);
		if(null!=result){
			JsapiTicket jsapiTicket=(JsapiTicket) JsonUtil.jsonToBean(result, JsapiTicket.class);
			System.out.println(jsapiTicket.getTicket());
			return jsapiTicket.getTicket();
		}
		return null;
	}
	
	public static void main(String[] args) {
		JsSign.getJsapiTicket();
	}
}

